#pragma once
#include <iostream>
#include <vector>
#include <string>
#include "../comm/Log.hpp"
#include "../comm/util.hpp"
#include <ctemplate/template.h>

namespace oj_View
{
    using namespace oj_model;
    static const std::string template_html = "./template_html";
    class View
    {
    public:
        View()
        {
        }
        ~View()
        {
        }

        void AllExpend(const vector<Question> &all, std::string *html)
        {
            std::string src_html = template_html + "/all_questions.html";
            ctemplate::TemplateDictionary root("all_questions");

            for (const auto &q : all)
            {
            //    待会回去把循环加上再试试，不行就注释了
                ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", q._num);
                sub->SetValue("title", q._title);
                sub->SetValue("star", q._star);
            }
            // for (const auto &q : all)
            // {
            //     root.SetValue("number", q._num);
            //     root.SetValue("title", q._title);
            //     root.SetValue("star", q._star);
            // }

            ctemplate::Template *template_ptr = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);

            template_ptr->Expand(html, &root);
        }

        void OneExpend(const Question& q, std::string *html)
        {
            std::string src_html = template_html + "/one_question.html";
            ctemplate::TemplateDictionary root("one_question");

            root.SetValue("number", q._num);
            root.SetValue("title", q._title);
            root.SetValue("star", q._star);
            root.SetValue("desc", q._desc);
            root.SetValue("header", q._header);

            ctemplate::Template *template_ptr = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);

            template_ptr->Expand(html, &root);
        }
    };
};